package com.huawei.esdk.uc.sametime.widgets;

import org.apache.log4j.Logger;
import org.eclipse.swt.widgets.Composite;

import com.ibm.collaboration.realtime.people.Person;
import com.ibm.collaboration.realtime.quickfind.QuickFindResult;
import com.ibm.collaboration.realtime.quickfind.ui.QuickFindWidget;

public class CustomQuickFindWidget extends QuickFindWidget
{

    private Logger logger = Logger.getLogger(CustomQuickFindWidget.class);
    
    private PersonSelectHandlerInterface handler;

    public CustomQuickFindWidget(Composite paramComposite, int paramInt)
    {
        super(paramComposite, paramInt);
    }

    @Override
    public boolean handleSelection(QuickFindResult paramQuickFindResult)
    {
        Object tempData = paramQuickFindResult.getData();
        if (tempData instanceof Person)
        {
            Person selectedPerson = (Person) tempData;
            String name = selectedPerson.getDisplayName();
            
            logger.debug("person " + name + " selected");
            
            if(null!=handler)
            {
                handler.handlePersonSelect(selectedPerson);
            }
            return true;
        }
        else
        {
            logger.debug("unknown data type");
            return false;
        }

    }

    public PersonSelectHandlerInterface getHandler()
    {
        return handler;
    }

    public void setHandler(PersonSelectHandlerInterface handler)
    {
        this.handler = handler;
    }
}
